<?php

namespace api\controller;

// +----------------------------------------------------------------------
// | 客户数据控制层
// +----------------------------------------------------------------------

use common\controller\VerifyController;
use common\exception\LogicException;
use common\service\CustomerService;
use think\Request;

class CustomerController extends VerifyController
{
    /**
     * @var CustomerService
     */
    private $customerService;

    public function __construct()
    {
        parent::__construct();
        $this->customerService = new CustomerService();
    }

    /**
     * 获取客户列表
     * @param Request $request
     * @return \think\Response
     */
    public function select(Request $request)
    {
        $param = $request->param();
        $resParam = [];
        if (array_key_exists('param', $param)) {
            $resParam = $param['param'];
        }
        try {
            $resData = $this->customerService->getCustomerList($request->getUserId(), $resParam, $request->tenantId);
            return json(success_response('', $resData));
        } catch (LogicException $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
    }

    /**
     * @param Request $request
     * @return \think\Response
     */
    public function find(Request $request)
    {
        $param = $request->param();
        $resParam = [];
        if (array_key_exists('param', $param)) {
            $resParam = $param['param'];
        }
        try {
            $resData = $this->customerService->getCustomer($request->getTenantId(), $resParam);
            return json(success_response('', $resData));
        } catch (LogicException $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
    }
}